// 这是订单模块。包含有state、types、actions、reducer等内容

// 初识话仓库
const initState = {
  list: [
    {name: 'san'}
  ]
}

// 统一处理类型
const types = {
  ADDORDER: 'ADDORDER',
  DELORDER: 'DELORDER',
}

// 统一生成action
export const actions = {
  addOrder: (order)=> ({type: types.ADDORDER, order: order}),
  delOrder: (index)=> ({type: types.DELORDER, index: index})
}

// 统一管理这个模块的数据
export const getList = (state)=> {
  return state.order.list
}
// 修改数据
const reducer = (state=initState, action)=> {
  switch (action.type) {
    case types.ADDORDER:
      return {
        ...state,
        list: [...state.list, action.order.order]
      }
    case types.DELORDER:
      state.list.splice(action.index, 1);
      return {
        list: [...state.list]
      }
    default:
      return state
  }
}

export default reducer